package com.ajx.ablibrary.net;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;

/**
 * Created by lai on 2017/9/12.
 */

public class ApiBase {
    protected static IApiService getService(String ip, long readTime, long connectTime) {

        OkHttpClient client = new OkHttpClient.Builder()
                .readTimeout(readTime <= 0 ? 10 : readTime, TimeUnit.SECONDS)
                .connectTimeout(connectTime <= 0 ? 10 : connectTime, TimeUnit.SECONDS)
                .addInterceptor(new RetryIntercepter(3))
                .build();
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(ip)
                .client(client)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();

        return retrofit.create(IApiService.class);
    }
}
